Commit Diff


commit - 1e4ab6d2a86a556879d4c29a8c23a79bf12ab430
commit + 9a0dc68bab2d2c0a9563e7c459804aa0c803a420
blob - 35887bf88046dd1ff00fb21ee83241b4d208ace8
blob + 1ea55a23fcb3891b16a9dce363b5118dffaf916b
--- README.md
+++ README.md
@@ -96,6 +96,14 @@ noopener noreferrer external
 
 Блок `head` может быть переопределён, если требуется добавить дополнительные элементы в `<head>`.
 
+Если сайт должен публиковать Markdown-представление страниц, `baseof.html` следует переопределить в самом сайте и добавить вызов:
+
+```go-html-template
+{{- partial "publish/markdown.html" . -}}
+```
+
+Hugo переопределяет `baseof.html` целиком, поэтому в сайт следует скопировать базовый шаблон темы и добавить вызов partial, например в конце шаблона.
+
 ## Partials
 
 ### attrs
@@ -256,6 +264,46 @@ SVG дополнительно минифицируеÑ
 ) -}}
 ```
 
+### publish/security-txt
+
+Генерирует ресурс `.well-known/security.txt` по RFC 9116.
+
+Страница с политикой безопасности определяется самим сайтом. Её параметры security.txt находятся в:
+
+```text
+.Params.security
+```
+
+Стандартный параметр страницы `expiryDate` используется для поля `Expires`.
+
+Partial возвращает Hugo Resource, поэтому публиковать его следует из `layouts/home.html` самого сайта:
+
+```go-html-template
+{{- (partial "publish/security-txt.html" (site.GetPage "/security")).Publish -}}
+```
+
+Если страница безопасности находится по другому пути, передайте соответствующую страницу в `site.GetPage`.
+
+При многоязычной сборке одного домена вызов следует выполнять только один раз, чтобы разные языковые версии не пытались опубликовать один и тот же файл `.well-known/security.txt`.
+
+### publish/markdown
+
+Публикует Markdown-представление Markdown-страницы рядом с её основным HTML output, заменяя расширение основного файла на `.md`.
+
+Например:
+
+```text
+/company/              → company/index.md
+/company/security/     → company/security/index.md
+/company/security.html → company/security.md
+```
+
+Partial предназначен для вызова из переопределённого в самом сайте `baseof.html`:
+
+```go-html-template
+{{- partial "publish/markdown.html" . -}}
+```
+
 ### logo
 
 Отображает логотип со ссылкой.
blob - /dev/null
blob + 795124e37eaa507e3cfc08c5f96c882164f1c16f (mode 644)
--- /dev/null
+++ layouts/_partials/publish/publish-markdown.html
@@ -0,0 +1,28 @@
+{{- $page := . -}}
+
+{{- with $page.File -}}
+  {{- if eq .Ext "md" -}}
+
+    {{- with $page.OutputFormats.Get "html" -}}
+      {{- $path := (urls.Parse .RelPermalink).Path -}}
+
+      {{- if strings.HasSuffix $path "/" -}}
+        {{- $path = printf "%sindex.html" $path -}}
+      {{- end -}}
+
+      {{- $extension := path.Ext $path -}}
+      {{- $path = printf
+        "%s.md"
+        (strings.TrimSuffix $extension $path)
+      -}}
+
+      {{- $resource := resources.FromString
+        (strings.TrimPrefix "/" $path)
+        $page.RenderShortcodes
+      -}}
+
+      {{- $resource.Publish -}}
+    {{- end -}}
+
+  {{- end -}}
+{{- end -}}
blob - /dev/null
blob + d323440cdd3a6bc1c0c33893d31a252f44c08634 (mode 644)
--- /dev/null
+++ layouts/_partials/publish/security-txt.html
@@ -0,0 +1,170 @@
+{{- $page := . -}}
+{{- $result := resources.FromString ".well-known/security.txt" "" -}}
+
+{{- if not $page -}}
+
+  {{- errorf "security.txt: security page not found, not published, or expired" -}}
+
+{{- else -}}
+
+  {{- $params := $page.Params.security -}}
+  {{- $valid := true -}}
+
+  {{- if not $params -}}
+    {{- errorf "security.txt: page %q must define params.security" $page.Path -}}
+    {{- $valid = false -}}
+  {{- end -}}
+
+  {{- if $page.ExpiryDate.IsZero -}}
+    {{- errorf "security.txt: page %q must define expiryDate" $page.Path -}}
+    {{- $valid = false -}}
+  {{- else if not ($page.ExpiryDate.After now) -}}
+    {{- errorf
+      "security.txt: page %q expired on %s"
+      $page.Path
+      ($page.ExpiryDate.Format "2006-01-02")
+    -}}
+    {{- $valid = false -}}
+  {{- end -}}
+
+  {{- if and $params (not $params.contact) -}}
+    {{- errorf "security.txt: page %q must define params.security.contact" $page.Path -}}
+    {{- $valid = false -}}
+  {{- end -}}
+
+
+  {{- if $valid -}}
+
+    {{- $lines := slice -}}
+
+    {{/*
+      URI fields.
+
+      Relative values such as /vacancy/ are interpreted as Hugo pages.
+      Absolute URIs such as mailto:, tel:, https:, openpgp4fpr:, etc.
+      are passed through unchanged.
+    */}}
+
+    {{- $fields := slice
+      (dict "name" "Contact" "values" $params.contact)
+      (dict "name" "Encryption" "values" $params.encryption)
+      (dict "name" "Acknowledgments" "values" $params.acknowledgments)
+      (dict "name" "Policy" "values" ($params.policy | default $page.RelPermalink))
+      (dict "name" "Hiring" "values" $params.hiring)
+    -}}
+
+    {{- range $field := $fields -}}
+
+      {{- with $field.values -}}
+
+        {{- $values := . -}}
+
+        {{- if not (reflect.IsSlice $values) -}}
+          {{- $values = slice $values -}}
+        {{- end -}}
+
+        {{- range $values -}}
+
+          {{- $value := printf "%v" . -}}
+          {{- $url := urls.Parse $value -}}
+
+          {{- if not $url.IsAbs -}}
+
+            {{- $target := $page -}}
+
+            {{- with $url.Path -}}
+              {{- $target = $page.Site.GetPage . -}}
+            {{- end -}}
+
+            {{- if not $target -}}
+
+              {{- errorf
+                "security.txt: %s references page %q which does not exist, is not published, or has expired"
+                $field.name
+                $value
+              -}}
+
+            {{- else -}}
+
+              {{- if and
+                (not $target.ExpiryDate.IsZero)
+                (not ($target.ExpiryDate.After now))
+              -}}
+                {{- errorf
+                  "security.txt: %s references expired page %q"
+                  $field.name
+                  $value
+                -}}
+              {{- end -}}
+
+              {{- $value = $target.Permalink -}}
+
+              {{- with $url.RawQuery -}}
+                {{- $value = printf "%s?%s" $value . -}}
+              {{- end -}}
+
+              {{- with $url.Fragment -}}
+                {{- $value = printf "%s#%s" $value . -}}
+              {{- end -}}
+
+            {{- end -}}
+
+          {{- end -}}
+
+          {{- $lines = $lines | append (printf
+            "%s: %s"
+            $field.name
+            $value
+          ) -}}
+
+        {{- end -}}
+
+      {{- end -}}
+
+    {{- end -}}
+
+
+    {{/* Expires */}}
+
+    {{- $lines = $lines | append (printf
+      "Expires: %s"
+      ($page.ExpiryDate.UTC.Format "2006-01-02T15:04:05Z")
+    ) -}}
+
+
+    {{/* Preferred-Languages */}}
+
+    {{- with $params.preferred_languages -}}
+
+      {{- $languages := . -}}
+
+      {{- if not (reflect.IsSlice $languages) -}}
+        {{- $languages = slice $languages -}}
+      {{- end -}}
+
+      {{- $lines = $lines | append (printf
+        "Preferred-Languages: %s"
+        (delimit $languages ", ")
+      ) -}}
+
+    {{- end -}}
+
+
+    {{/* Canonical */}}
+
+    {{- $lines = $lines | append (printf
+      "Canonical: %s"
+      ("/.well-known/security.txt" | absURL)
+    ) -}}
+
+
+    {{- $result = resources.FromString
+      ".well-known/security.txt"
+      (printf "%s\n" (delimit $lines "\n"))
+    -}}
+
+  {{- end -}}
+
+{{- end -}}
+
+{{- return $result -}}
blob - d323440cdd3a6bc1c0c33893d31a252f44c08634 (mode 644)
blob + /dev/null
--- layouts/_partials/security-txt.html
+++ /dev/null
@@ -1,170 +0,0 @@
-{{- $page := . -}}
-{{- $result := resources.FromString ".well-known/security.txt" "" -}}
-
-{{- if not $page -}}
-
-  {{- errorf "security.txt: security page not found, not published, or expired" -}}
-
-{{- else -}}
-
-  {{- $params := $page.Params.security -}}
-  {{- $valid := true -}}
-
-  {{- if not $params -}}
-    {{- errorf "security.txt: page %q must define params.security" $page.Path -}}
-    {{- $valid = false -}}
-  {{- end -}}
-
-  {{- if $page.ExpiryDate.IsZero -}}
-    {{- errorf "security.txt: page %q must define expiryDate" $page.Path -}}
-    {{- $valid = false -}}
-  {{- else if not ($page.ExpiryDate.After now) -}}
-    {{- errorf
-      "security.txt: page %q expired on %s"
-      $page.Path
-      ($page.ExpiryDate.Format "2006-01-02")
-    -}}
-    {{- $valid = false -}}
-  {{- end -}}
-
-  {{- if and $params (not $params.contact) -}}
-    {{- errorf "security.txt: page %q must define params.security.contact" $page.Path -}}
-    {{- $valid = false -}}
-  {{- end -}}
-
-
-  {{- if $valid -}}
-
-    {{- $lines := slice -}}
-
-    {{/*
-      URI fields.
-
-      Relative values such as /vacancy/ are interpreted as Hugo pages.
-      Absolute URIs such as mailto:, tel:, https:, openpgp4fpr:, etc.
-      are passed through unchanged.
-    */}}
-
-    {{- $fields := slice
-      (dict "name" "Contact" "values" $params.contact)
-      (dict "name" "Encryption" "values" $params.encryption)
-      (dict "name" "Acknowledgments" "values" $params.acknowledgments)
-      (dict "name" "Policy" "values" ($params.policy | default $page.RelPermalink))
-      (dict "name" "Hiring" "values" $params.hiring)
-    -}}
-
-    {{- range $field := $fields -}}
-
-      {{- with $field.values -}}
-
-        {{- $values := . -}}
-
-        {{- if not (reflect.IsSlice $values) -}}
-          {{- $values = slice $values -}}
-        {{- end -}}
-
-        {{- range $values -}}
-
-          {{- $value := printf "%v" . -}}
-          {{- $url := urls.Parse $value -}}
-
-          {{- if not $url.IsAbs -}}
-
-            {{- $target := $page -}}
-
-            {{- with $url.Path -}}
-              {{- $target = $page.Site.GetPage . -}}
-            {{- end -}}
-
-            {{- if not $target -}}
-
-              {{- errorf
-                "security.txt: %s references page %q which does not exist, is not published, or has expired"
-                $field.name
-                $value
-              -}}
-
-            {{- else -}}
-
-              {{- if and
-                (not $target.ExpiryDate.IsZero)
-                (not ($target.ExpiryDate.After now))
-              -}}
-                {{- errorf
-                  "security.txt: %s references expired page %q"
-                  $field.name
-                  $value
-                -}}
-              {{- end -}}
-
-              {{- $value = $target.Permalink -}}
-
-              {{- with $url.RawQuery -}}
-                {{- $value = printf "%s?%s" $value . -}}
-              {{- end -}}
-
-              {{- with $url.Fragment -}}
-                {{- $value = printf "%s#%s" $value . -}}
-              {{- end -}}
-
-            {{- end -}}
-
-          {{- end -}}
-
-          {{- $lines = $lines | append (printf
-            "%s: %s"
-            $field.name
-            $value
-          ) -}}
-
-        {{- end -}}
-
-      {{- end -}}
-
-    {{- end -}}
-
-
-    {{/* Expires */}}
-
-    {{- $lines = $lines | append (printf
-      "Expires: %s"
-      ($page.ExpiryDate.UTC.Format "2006-01-02T15:04:05Z")
-    ) -}}
-
-
-    {{/* Preferred-Languages */}}
-
-    {{- with $params.preferred_languages -}}
-
-      {{- $languages := . -}}
-
-      {{- if not (reflect.IsSlice $languages) -}}
-        {{- $languages = slice $languages -}}
-      {{- end -}}
-
-      {{- $lines = $lines | append (printf
-        "Preferred-Languages: %s"
-        (delimit $languages ", ")
-      ) -}}
-
-    {{- end -}}
-
-
-    {{/* Canonical */}}
-
-    {{- $lines = $lines | append (printf
-      "Canonical: %s"
-      ("/.well-known/security.txt" | absURL)
-    ) -}}
-
-
-    {{- $result = resources.FromString
-      ".well-known/security.txt"
-      (printf "%s\n" (delimit $lines "\n"))
-    -}}
-
-  {{- end -}}
-
-{{- end -}}
-
-{{- return $result -}}